// 引入相关模块
var http = require('http');
var url = require("url");
var path = require("path");

// 创建server
var server = http.createServer((req, res) => {
    // 请求路径
    var pathname = url.parse(req.url).pathname;
    res.writeHead(
        200,
        { "Content-Type": "application/json;charset=utf-8" }
    )
    // 设定路由
    switch (pathname) {
        case "":
        case "/":
        case "/index":
            res.end(JSON.stringify({ "index": "欢迎来到首页" }));
            break;
        case "/health.json":
            res.end(JSON.stringify({ "status": "UP" }));
            break;
        default:
            res.end("404");
    }
})

// 设置监听
server.listen(8866, () => { console.log("listening on localhost:8866") });
